package utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBHelper {
   public static  Connection conn = null;
   public static String url = "jdbc:mysql://localhost:3306/db_order";
    public static Connection getConnection() {
    	try {
			Class.forName("com.mysql.cj.jdbc.Driver");
			conn = DriverManager.getConnection(url, "root", "123456");
		     return conn;
    	} catch (ClassNotFoundException e) {
    		System.out.println(e.getMessage());
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			System.out.println(e.getMessage());
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	return conn;
    }
    
    public static void main(String[] args) {
    	Connection c = getConnection();
    	if(c != null) {
    		System.out.println("数据库连接成功" + c);
    	}
    	
	}
}
